import { ZFormItemSchema } from "@/components/Form/typings";
import {
  boolRender,
  enumRender,
  secondsTimestampRender,
} from "@/components/Table/helpers/renders";
import { ZTableColumn } from "@/components/Table/typings";
import { hash2Options } from "@/utils";
import { MatchType } from "../helpers";

export const getColumns = (): ZTableColumn[] => [
  {
    title: "词ID",
    key: "id",
  },
  {
    title: "敏感词",
    key: "word",
  },
  {
    title: "生效语言",
    key: "language",
  },
  {
    title: "是否正则",
    key: "is_regex",
    render: boolRender,
  },
  {
    title: "匹配方式",
    key: "match_type",
    render: enumRender(MatchType),
    filterMultiple: true,
    filterOptions: hash2Options(MatchType),
    filter: "default",
  },
  {
    title: "生效地区",
    key: "region",
  },
  {
    title: "豁免地区",
    key: "exempt_region",
  },
  {
    title: "豁免语言",
    key: "exempt_language",
  },
  {
    title: "创建人",
    key: "creator",
  },
  {
    title: "创建时间",
    key: "create_time",
    render: secondsTimestampRender,
    sorter: true,
  },
];

export const getSearchSchemas = (): ZFormItemSchema[] => [
  {
    label: "敏感词",
    path: "word",
    span: 16,
  },
];

export const getEditSchemas = (): ZFormItemSchema[] => [
  {
    label: "敏感词",
    path: "word",
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "是否正则",
    path: "is_regex",
    component: "ZRadioGroup",
    componentProps: {
      options: [
        { label: "是", value: 1 },
        { label: "否", value: 0 },
      ],
      disabled: true,
    },
  },
  {
    label: "生效语言",
    path: "language",
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "匹配方式",
    path: "match_type",
    component: "NSelect",
    componentProps: {
      options: hash2Options(MatchType, true),
    },
  },
  {
    label: "生效地区",
    path: "region",
    required: true,
  },
  {
    label: "豁免地区",
    path: "exempt_region",
  },
  {
    label: "单向豁免词",
    path: "one_way_words",
    component: "NInput",
    componentProps: {
      type: "textarea",
      placeholder: "",
    },
  },
  {
    label: "双向豁免词",
    path: "two_way_words",
    component: "NInput",
    componentProps: {
      type: "textarea",
      placeholder: "",
    },
  },
  {
    label: "失效时间",
    path: "expire_time",
    component: "NDatePicker",
  },
];
